package com.dzk.cp.c11x5.catcher.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dzk.cp.c11x5.constant.C11x5Constants;
import com.dzk.cp.c11x5.dao.R5Dao;
import com.dzk.cp.c11x5.pojo.GdR5;
import com.dzk.cp.util.PropsUtils;

@Service("gdCodeCatcherService")
public class GdCodeCatcherServiceImpl extends CodeCatcherServiceImpl<GdR5> {
	
	@Resource(name="gdR5DaoJdbc")
	private R5Dao<GdR5> r5Dao;
	
	@Override
	public void catchCodeByDate(String date) {
		Map<String, String> codeMap = super.getCodesByDate(this.getByDateURL(new Object[] {1, date}), null);
		codeMap.putAll(super.getCodesByDate(this.getByDateURL(new Object[] {2, date}), null));
		for (String issue : codeMap.keySet()) {
			GdR5 r5 = this.createR5(issue, codeMap.get(issue), this.getEntityClass());
			this.getR5Dao().save(r5);
		}
	}
	
	@Override
	protected Class<GdR5> getEntityClass() {
		return GdR5.class;
	}

	@Override
	protected R5Dao<GdR5> getR5Dao() {
		return r5Dao;
	}

	@Override
	protected String getByDateURL(Object... params) {
		return PropsUtils.getProperty(C11x5Constants.GD11X5_QUERY_BYDATE_URL, params);
	}

	@Override
	protected String getByIssueURL(Object... params) {
		return PropsUtils.getProperty(C11x5Constants.GD11X5_QUERY_BYISSUE_URL, params);
	}
	
//	public static void main(String[] args) {
//		GdCodeCatcherServiceImpl a = new GdCodeCatcherServiceImpl();
//		a.getCodesByDate("http://cp.360.cn/kaijiang/kjlist?LotID=165707&Page=1&QueryDate=2013-07-01", null);
//	}

}
